# konrad.smolinski@gmail.com
# date: 		1/12/2010
# last update: 	13/05/2010
#
# info:
#
#
# ------------------------------------------------------------------
rcGetLHS <- function(abGrid,qs,loIdx,xval){
	
	lhs <- rep(0,length(loIdx))
	res <- matrix(0,nrow=nrow(abGrid),ncol=length(loIdx))
		
		for(g in 1:nrow(abGrid)){
			lhs <- rep(0,length(loIdx))
			intVec <- rcBaseIntegrate(a=abGrid[g,1:2],b=abGrid[g,3:4],xval=xval,quadPt=qs)

			for(i in 1:length(loIdx))	lhs[i] <- sum(intVec[loIdx[[i]]])
			 res[g,] <- lhs 
			cat(".")
		}
	
return(res)	
}
# ------------------------------------------------------------------
# Validate
# integrand over Base 'Components'
# this part depends on the initial parameters

codeVal <- FALSE
if(codeVal){
	cat("\n Validate: rcGetLHS() : \n\n")
	# GRID
	a1seq <- seq(-0.2,0.5,len=6)
	a2seq <- seq(0.1,1.6,len=6)
	b1seq <- seq(0,0,len=1)
	b2seq <- seq(0.1,1.6,len=4)

	xval <- c(0,1)
	loIdx <- rcLeaveOutIdx(length(xval))
	qs <- smolyak.quad(2,40)


	abGrid <- as.matrix(expand.grid(a1seq,a2seq,b1seq,b2seq))
	lhs <- rcGetLHS(abGrid,qs,loIdx,xval)
	lhs
}
